package com.gitee.sparta.caffeine;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.stats.CacheStats;

import java.util.concurrent.TimeUnit;

/**
 * <p>
 * </p>
 *
 * @author zyred
 * @since v 0.0.1
 */
public class ExampleCaffeine {

    public static void main(String[] args) {
        Cache<String, String> cache = Caffeine.newBuilder()
                .maximumSize(10_000)
                .expireAfterAccess(10, TimeUnit.MINUTES)
                .recordStats()
                .build();

        // 模拟数据访问
        cache.put("键1", "值1");
        String value = cache.getIfPresent("键1");

        // 获取并打印统计信息
        CacheStats stats = cache.stats();
        System.out.println("命中率：" + stats.hitRate());
    }

}
